<?php
//Fungsi convert tanggal ke tanggalan indonesia
function indDate($date) 
{
	$arr_bulan = array("Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "Nopember", "Desember");
	$arr_date = explode("-", $date);
	$arr_date[1] = intval($arr_date[1]);
	$arr_date[2] = intval($arr_date[2]);
	return $arr_date[2].' '.$arr_bulan[$arr_date[1] - 1].' '.$arr_date[0];
}
// untuk menampilkan dropdown kelas
function classDropdown($table=FALSE,$id=FALSE,$limit=FALSE,$var_name=FALSE,$val_id=FALSE,$field_name=FALSE,$width=FALSE,$selected=FALSE)
{
	$ci=& get_instance();
	$ci->db->where($id,$limit);
	$row = $ci->db->get($table)->result_array();
	$nama = ''.$field_name.'';
	$id = ''.$val_id.'';
    	$output = "<select class='' name='".$var_name."' style='width:'".$width."px';' id='kab_id'>";
		$output .= "<option value=''> - Pilih - </option>";
		    foreach($row as $row):
		    	if($selected):
		    		if($row[$id]==$selected):
						$output .= "<option value='".$row[$id]."' selected='selected'>".$row[$nama]."</option>";
					else:
						$output .= "<option value='".$row[$id]."'>".$row[$nama]."</option>";
					endif;
		    	else:
		    		$output .= "<option value='".$row[$id]."'>".$row[$nama]."</option>";
		    	endif;
		    endforeach;
	    $output .= "</select>";
    return $output;
}
/*
function classDropdown($id_ivent=FALSE)
{
	$ci=& get_instance();
	$ci->db->where('id_event',$id_ivent);
	$kab = $ci->db->get('tk_class')->result_array();
	
	$output = "<select id='id_kab' class='contact_input' name='class' style='width:200px;'>";
			$output .= "<option value=''> - Pilih Kelas- </option>";
		    foreach($kab as $kab):
		    
		    		$output .= "<option value='".$kab["id_event"]."'>".$kab['class_name']."</option>";
		    	
		    endforeach;
	$output .= "</select>";
	return $output;
} */
/*
fungsi dropdown umum yg mengambil data dari database
dataTableDropdown('nama_tabel','name_field_inputnya','option_valuenya','nama_tampil_field','terpilih=id_nya')
*/

function dataTableDropdown($table=FALSE,$var_name=FALSE,$val_id=FALSE,$field_name=FALSE,$width=FALSE,$selected=FALSE)
{
	$ci=& get_instance();
	$row = $ci->db->get($table)->result_array();
	$nama = ''.$field_name.'';
	$id = ''.$val_id.'';
    	$output = "<select class='' name='".$var_name."' style='width:'".$width."px';' id='kab_id'>";
		$output .= "<option value=''> - Pilih - </option>";
		    foreach($row as $row):
		    	if($selected):
		    		if($row[$id]==$selected):
						$output .= "<option value='".$row[$id]."' selected='selected'>".$row[$nama]."</option>";
					else:
						$output .= "<option value='".$row[$id]."'>".$row[$nama]."</option>";
					endif;
		    	else:
		    		$output .= "<option value='".$row[$id]."'>".$row[$nama]."</option>";
		    	endif;
		    endforeach;
	    $output .= "</select>";
    return $output;
}



function dateDropdown($name,$date=FALSE,$th_st=FALSE,$th_end=FALSE)
{
	$ci=& get_instance();
	if($date){
	$dt = explode('-',$date);
	$year = $dt[0];
	$mon = $dt[1];
	$day = $dt[2];
	}
	
	$ret = '<select class="sel_input" name="'.$name.'_d"  style="width:50px;">';
	for ($i=1;$i<32;$i++):
		$val=$i;
		if($val < 10):
			$val = '0'.$val;
		endif;
		if ($date):
			if($val == $day):
				$ret .= '<option value="'.$val.'" selected="selected">'.$i.'</option>';
			else:
				$ret .= '<option value="'.$val.'">'.$i.'</option>';
			endif;
		else:
			$ret .= '<option value="'.$val.'">'.$i.'</option>';
		endif;
	endfor;
	$ret .='</select> ';

	$month = array	('Jan','Feb','Mar','Apr','Mei','Jun','Jul','Ags','Sep','Okt','Nov','Des');
	$ret .= '<select class="sel_input" name="'.$name.'_m"  style="width:60px;">';
	for ($i=0;$i<12;$i++):
		$val=$i+1;
		if($val < 10):
			$val = '0'.$val;
		endif;
		if ($date):
			if($val == $mon):
				$ret .= '<option value="'.$val.'" selected="selected">'.$month[$i].'</option>';
			else:
				$ret .= '<option value="'.$val.'">'.$month[$i].'</option>';
			endif;
		else:
			$ret .= '<option value="'.$val.'">'.$month[$i].'</option>';
		endif;
	endfor;
	$ret .='</select> ';
	

	$minyear = $th_st;
	$plusyear = $th_end;

	$ret .= '<select class="sel_input" name="'.$name.'_y" style="width:64px;">';
	for ($i=$minyear;$i<=$plusyear;$i++):
		if ($date):
			if($i==$year):
				$ret .= '<option value="'.$i.'" selected="selected">'.$i.'</option>';
			else:
				$ret .= '<option value="'.$i.'">'.$i.'</option>';
			endif;
		else:
			$ret .= '<option value="'.$i.'">'.$i.'</option>';
		endif;
	endfor;
	$ret .='</select>';
return $ret;

}

// nVn : DropDown untuk Jenis kelamin yang digunakan pada /backend/member
function sexDropdown($selected)
{
	$options = array(
                  'Pria'=> 'Pria',
				  'Wanita'=> 'Wanita'
                );
	$class = 'class="title"';
	return form_dropdown('sex',$options,$selected,$class);
} 



function statusMemberDropdown($selected)
{
	$options = array(
                  '1'=> 'Aktif',
				  '0'=> 'Block'
                );
	$class = 'class="search_input"';
	return form_dropdown('stat_mem',$options,$selected,$class);
} 

function ratingStatDropdown($selected)
{
	
	$options = array(
                  'approve'=> 'approve',
                  'unapprove' => 'unapprove'
                );
	$class = 'class="search_input"';
	return form_dropdown('rat_stat',$options,$selected,$class);
}    


function kabDropdown($prov_id=FALSE,$id_kab=FALSE)
{
	$ci=& get_instance();
	$ci->db->where('id_province',$prov_id);
	$kab = $ci->db->get('tk_kab')->result_array();
	
	$output = "<select id='id_kab' class='contact_input' name='id_kab' style='width:200px;'>";
			$output .= "<option value=''> - Pilih - </option>";
		    foreach($kab as $kab):
		    	if($id_kab):
		    		if($kab["id_kab"]==$id_kab):
						$output .= "<option value='".$kab["id_kab"]."' selected='selected'>".$kab['nm_kab']."</option>";
					else:
						$output .= "<option value='".$kab["id_kab"]."'>".$kab['nm_kab']."</option>";
					endif;
		    	else:
		    		$output .= "<option value='".$kab["id_kab"]."'>".$kab['nm_kab']."</option>";
		    	endif;
		    endforeach;
	$output .= "</select>";
	return $output;
}

function provDropdown($selected=FALSE)
{
	$ci=& get_instance();
	$ci->db->select('id_province,nm_province');
	$row = $ci->db->get('tk_province')->result_array();
    	$output = "<select id='id_province' class='contact_input' name='id_province' onChange='kabDropdown(this.value)'>";
			$output .= "<option value=''> - Pilih - </option>";
		    foreach($row as $row):
		    	if($selected):
		    		if($row["id_province"]==$selected):
						$output .= "<option value='".$row["id_province"]."' selected='selected'>".$row['nm_province']."</option>";
					else:
						$output .= "<option value='".$row["id_province"]."'>".$row['nm_province']."</option>";
					endif;
		    	else:
		    		$output .= "<option value='".$row["id_province"]."'>".$row['nm_province']."</option>";
		    	endif;
		    endforeach;
	    $output .= "</select>";
    return $output;
}


function diskonDropdown()
{
	$ci=& get_instance();
	$id = $ci->uri->segment(4);
	
	if($id!=''):
		$row = $ci->Produk_model->getProduk(FALSE,$id,FALSE,FALSE);
		$disk = $row->diskon;
	else:
		$disk = 0;
	endif;
	
	$ret = "<select id='diskon' name='diskon'>";
	for ($i=0;$i<=10;$i++):
		$val=$i*1;
		if($val == $disk):
			$val = $disk;
			$ret .= '<option value="'.$val.'" selected="selected">'.$val.'</option>';
		else:
			$ret .= '<option value="'.$val.'">'.$val.'</option>';
		endif;
	endfor;
	$ret .='</select> ';
	return $ret;
}


function kontenDropdown($selected)
{
	$options = array(
                  'tentang-kami'=> 'Tentang Kami',
                  'terms' => 'Terms and Condition',
				  'terms-order' => 'Terms and Condition Order',
				  'cara-transaksi' => 'Cara Transaksi',
                  'faq' => 'FAQ'
                );
	return form_dropdown('page',$options,$selected);
}

function ruleDropdown($selected)
{
	$options = array(
                  'Manager'=> 'Manager',
                  'Administrator' => 'Administrator',
				  'Sales' => 'Sales',
                );
	return form_dropdown('user_rule',$options,$selected);
}

function dropDownBank($selected=FALSE)
{
		$ci=& get_instance();
		
		$row = $ci->db->get('tb_bank')->result_array();
		$output = "<select id='bank_id' class='contact_input' name='bank_id'>";
		foreach($row as $row):
			if($selected):
				if($row["bank_id"]==$selected):
						$output .= "<option value='".$row["bank_id"]."' selected='selected'>".$row['nama_rek']." - ".$row['nama_bank']." - ".$row['no_rek']."</option>";
					else:
						$output .= "<option value='".$row["bank_id"]."'>".$row['nama_rek']." - ".$row['nama_bank']." - ".$row['no_rek']."</option>";
					endif;
		    	else:
					$output .= "<option value='".$row["bank_id"]."'>".$row['nama_rek']." - ".$row['nama_bank']." - ".$row['no_rek']."</option>";
			endif;
		endforeach;
		$output .= "</select>";
		return $output;
}


function getBerita()
{
	$ci=& get_instance();
	$ci->db->where('page','berita');
	$ci->db->where('published','Ya');
	$ci->db->limit(3);
	$ci->db->order_by('konten_id','desc');
	$query = $ci->db->get('tb_konten');
	$res = $query->result_array();
	
	$i=1;
	foreach($res as $row):
		echo '<div class="news_list">';
			echo '<div class="news_title_list"><a href="#">'.$row['judul'].'</a></div>';
			echo '<strong>'.formatDate($row['date'],'short').'</strong>';
			echo character_limiter($row['isi_konten'],200);
			echo '<a href="#news'.$i.'" rel="facebox">more</a>';
		echo '</div>';
		
		echo '<div id="news'.$i.'" style="display:none">';
		echo '<strong>'.$row['judul'].'</strong><br />';
		echo '<strong>'.formatDate($row['date'],'short').'</strong><br />';
		echo $row['isi_konten'];
		echo '</div>';
	$i++;
	endforeach;
	echo '<a href='.site_url().'/konten/archive>Archive</a>';
	echo '<br /><br />';
	
	
}



function loadTinyMCE($ret='name')
{
	if($ret == 'simple'):
		$output = '
		<script type="text/javascript" src="'.base_url().'assets/js/tiny_mce/tiny_mce.js"></script>
		<script type="text/javascript">
		tinyMCE.init({
			// General options
			mode : "textareas",
			editor_selector : "mceEditor",

			theme : "advanced",
			plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave",

			// Theme options
			theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,|,undo,redo,|,bullist,numlist,outdent,indent,blockquote,|,link,unlink,|,pastetext,pasteword,|,preview",
			theme_advanced_buttons2 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,media,advhr,|,fullscreen",
			theme_advanced_buttons3 : "",
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_statusbar_location : "bottom",
			theme_advanced_resizing : true,
			theme_advanced_resize_horizontal : false,

			// Example content CSS (should be your site CSS)
			content_css : "'. base_url().'assets/js/tiny_mce/css/content.css",

		})
		</script>
		';
	elseif($ret=='medium'):
		$output = '
		<script type="text/javascript" src="'.base_url().'assets/js/tiny_mce/tiny_mce.js"></script>
			<script type="text/javascript">
				tinyMCE.init({
					// General options
					mode : "textareas",
					editor_selector : "mceEditor",
					relative_urls : false,
					remove_script_host : false,
					document_base_url : "'.base_url().'",

					theme : "advanced",
					plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave",

					// Theme options
					theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,formatselect,|,cut,copy,paste,pastetext,pasteword",
					theme_advanced_buttons2 : "search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,code",
					theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,media,advhr,|,fullscreen",
					theme_advanced_buttons4 : "cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,|,insertdate,inserttime,preview,|,forecolor,backcolor",
					theme_advanced_toolbar_location : "top",
					theme_advanced_toolbar_align : "left",
					theme_advanced_statusbar_location : "bottom",
					theme_advanced_resizing : true,
					theme_advanced_resize_horizontal : false,

					// Example content CSS (should be your site CSS)
					content_css : "'.base_url().'assets/js/tiny_mce/css/content.css",

					// Drop lists for link/image/media/template dialogs
					template_external_list_url : "lists/template_list.js",
					external_link_list_url : "lists/link_list.js",
					external_image_list_url : "lists/image_list.js",
					media_external_list_url : "lists/media_list.js",

				});
			</script>
		';
	elseif($ret=='advance'):
		$output = '
		<script type="text/javascript" src="'.base_url().'assets/js/tiny_mce/tiny_mce.js"></script>
		<script type="text/javascript">
			tinyMCE.init({
				// General options
				mode : "textareas",
				theme : "advanced",
				plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave",

				// Theme options
				theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
				theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
				theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
				//theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft",
				theme_advanced_toolbar_location : "top",
				theme_advanced_toolbar_align : "left",
				theme_advanced_statusbar_location : "bottom",
				theme_advanced_resizing : true,

				// Example content CSS (should be your site CSS)
				content_css : "css/content.css",

				// Drop lists for link/image/media/template dialogs
				template_external_list_url : "lists/template_list.js",
				external_link_list_url : "lists/link_list.js",
				external_image_list_url : "lists/image_list.js",
				media_external_list_url : "lists/media_list.js",

				// Style formats
				style_formats : [
					{title : \'Bold text\', inline : \'b\'},
					{title : \'Red text\', inline : \'span\', styles : {color : \'#ff0000\'}},
					{title : \'Red header\', block : \'h1\', styles : {color : \'#ff0000\'}},
					{title : \'Example 1\', inline : \'span\', classes : \'example1\'},
					{title : \'Example 2\', inline : \'span\', classes : \'example2\'},
					{title : \'Table styles\'},
					{title : \'Table row 1\', selector : \'tr\', classes : \'tablerow1\'}
				],

				// Replace values for the template plugin
				template_replace_values : {
					username : "Some User",
					staffid : "991234"
				}
			});
		</script>
		';
	endif;
	return $output;
}


/**
* function makeslug
* digunakan untuk mereplace spasi ketika akan ditampilkan di url address
*/

function makeslug($string){
	$slug= strtolower(preg_replace('/[^A-Za-z0-9-]+/', '-', $string));
	$slug = str_replace(" ", "-", $slug);
	return $slug;
}
/**
* function memformat harga
* digunakan membuat format rupiaah
*/

function formatHarga($n,$lengkap=FALSE) {
	// first strip any formatting;
	$n = (0+str_replace(",","",$n));

	// is this a number?
	if(!is_numeric($n)) return false;

	if($lengkap)$n = number_format($n,0,",",".");
	// now filter it;
	else if($n>1000000000000) $n= number_format(round(($n/1000000000000),0,",","."),1).' trilyun';
	else if($n>1000000000) $n= number_format(round(($n/1000000000),0,",","."),1).' milyar';
	else if($n>1000000) $n= number_format(round(($n/1000000),1),0,",",".").' juta';
	else if($n>1000) $n= number_format(round(($n/1000),1),0,",",".").' ribu';

	return "Rp ".$n ;
}


/**
* function formatDate
* @uses mmemformat tanggal
*/
function formatDate($date, $format='name')
{
	$ci=& get_instance();

	if($format=='long'):
		$unix_date = human_to_unix($date);
		return date('l, jS F, Y - H:i:s',$unix_date);
	elseif($format=='medium1'):
		$unix_date = human_to_unix($date);
		return date('jS M, Y - H:i',$unix_date);
	elseif($format=='medium2'):
		$unix_date = human_to_unix($date);
		return date('jS F, Y',$unix_date);
	elseif($format=='short'):
		$unix_date = human_to_unix($date);
		return date('d-M-Y',$unix_date);
	elseif($format=='ampm'):
		$unix_date = human_to_unix($date);
		return date('d M Y g:ia',$unix_date);
	elseif($format=='short1'):
		$unix_date = human_to_unix($date);
		return date('d M Y - H:i:s',$unix_date);
	elseif($format=='rssdate'):
		$unix_date = human_to_unix($date);
		return date('D, j M Y H:i:s +0700',$unix_date);
	elseif($format=='sitemap_date'):
		$unix_date = human_to_unix($date);
		return date('Y-m-d',$unix_date);
	elseif($format=='admin_date'):
		$unix_date = human_to_unix($date);
		return date('d-M-Y',$unix_date);
	elseif($format=='cek'):
		$unix_date = human_to_unix($date);
		return date('Y-m-d',$unix_date);
	elseif($format=='year_only'):
		$unix_date = human_to_unix($date);
		return date('Y',$unix_date);
	elseif($format=='timespan'):
		$unix_date = human_to_unix($date);
		return timespan($unix_date,now());
	else:
		return false;
	endif;

}
/**
* function crop image
* @uses croping gambar agar lebih kecil, 
* menggunaklan lib dari ci -> GD2
*/

function cropImage($image,$size,$filename,$ext,$filepath)
{
	$ci =& get_instance();

	$image_size = getimagesize($image);
	$image_width = $image_size['0'];
	$image_height = $image_size['1'];

	$config['image_library'] = 'gd2';
	$config['source_image'] = $image;
	$config['new_image'] = $filename.'_'.$size.'x'.$size.$ext;
	$config['maintain_ratio'] = FALSE;
	if($image_width > $image_height):
		$config['height'] = $image_height;
		$config['width'] = $image_height;
	elseif($image_width < $image_height):
		$config['height'] = $image_width;
		$config['width'] = $image_width;
	else:
		$config['height'] = $image_width;
		$config['width'] = $image_width;
	endif;

	if($image_width > $image_height):
		$config['x_axis'] = (5/100)*$image_width;
		$config['y_axis'] = '0';
	elseif($image_width < $image_height):
		$config['x_axis'] = '0';
		$config['y_axis'] = (5/100)*$image_height;
	else:
		$config['x_axis'] = (5/100)*$image_width;
		$config['y_axis'] = '0';
	endif;
	$ci->image_lib->initialize($config);
	$ci->image_lib->crop();

	$ci->image_lib->clear();

	$config2['image_library'] = 'gd2';
	$config2['source_image'] = $filepath.$config['new_image'];
	$config2['maintain_ratio'] = TRUE;
	$config2['height'] = $size;
	$config2['width'] = $size;

	$ci->image_lib->initialize($config2);
	$ci->image_lib->resize();

	return $filename.'_150x150'.$ext;

}

/**
* function resize
* @uses merubah atau mengganti ukuran gambar
* menggunaklan lib dari ci -> GD2
*/

function resizeImage($image,$width,$height,$filename,$ext,$filepath)
{
	
	$ci =& get_instance();

	$config['image_library'] = 'gd2';
	$config['source_image'] = $image;
	$config['new_image'] = $filename.'_'.$width.'x'.$height.$ext;
	$config['maintain_ratio'] = TRUE;
	$config['height'] = $height;
	$config['width'] = $width;

	$ci->image_lib->initialize($config);
	$ci->image_lib->resize();

	$image_size = getimagesize($filepath.$config['new_image']);
	$image_width = $image_size['0'];
	$image_height = $image_size['1'];
	rename($filepath.$config['new_image'],$filepath.$filename.'_'.$image_width.'x'.$image_height.$ext);
	return $filename.'_'.$image_width.'x'.$image_height.$ext;
	$ci->image_lib->clear();
}


/**
* function page
* helper ketika data di hapus atau ditambah atau diedit agar kembali ke posisi page row yg di edit (pagination)
*/

function getPage($control=FALSE,$page=FALSE,$uri=FALSE,$count=FALSE)// 
{
	$ci=& get_instance();
	if ($page == 'add') // jka insert
	{
		$div = $count/$ci->config->item('per_page');// tergantung sama pagination nya.. 
		$mod = $count % $ci->config->item('per_page');// cari halaman yg ga ganjil
		
		$x = explode('.',$div);
		$y = $x[0];
		$last_page = $y * $ci->config->item('per_page');
		$minus = $last_page - $ci->config->item('per_page');
		$last_page2 = $minus;
		
		if ($mod == '0'):
		redirect('backend/'.$control.'/index/'.$last_page2);
		elseif ($count >= $ci->config->item('per_page')):
		redirect('backend/'.$control.'/index/'.$last_page);
		else:
		redirect('backend/'.$control.'/');
		endif;
	}
	elseif ($page == 'edit') // jika edit
	{
		$p = $uri - 1;
		if ($p == 0):
			$page = $uri;
		else:
			$page = $p;
		endif;
		
		$div = $page/$ci->config->item('per_page');
		$mod = $page % $page/$ci->config->item('per_page');
		$x = explode('.',$div);
		$y = $x[0];
		
		$edit_page = $y * $ci->config->item('per_page');
		$edit_page2 = $edit_page - $ci->config->item('per_page');
		$plus = $edit_page +1;

		if ($page < $ci->config->item('per_page')):
			redirect('backend/'.$control.'/');
		elseif ($page > $ci->config->item('per_page')):
			redirect('backend/'.$control.'/index/'.$edit_page);
		elseif (($page == $plus) || $mod == 0 ):
			redirect('backend/'.$control.'/index/'.$edit_page);
		endif;
	}
	elseif ($page == 'delete')// dan jika hapus
	{
		$p = $uri - 1;
		if ($p == 0):
			$page = $uri;
		else:
			$page = $p;
		endif;
					
		$div = $page/$ci->config->item('per_page');
		$mod = $page % $page/$ci->config->item('per_page');
		$x = explode('.',$div);
		$y = $x[0];
				
		$edit_page = $y * $ci->config->item('per_page');
		$edit_page2 = $edit_page - $ci->config->item('per_page');
		$plus = $edit_page +1;

		if ($page < $ci->config->item('per_page') || $count == $ci->config->item('per_page')):
			redirect('backend/'.$control.'/');
		elseif ($page >= $ci->config->item('per_page') ):
			redirect('backend/'.$control.'/index/'.$edit_page);
		elseif ((($page + 1) == $plus) || $mod == 0 ):
			redirect('backend/'.$control.'/index/'.$edit_page2);
		endif;
	}
}

// Fungsi untuk digunakan pada Marketing ->> ternyata sudah ada diatas, 
// jadi yang ini tidak dipakai.
function dropDownProvinsi($selected = false)
{
	$ci=& get_instance();
	$row = $ci->db->get('tk_province')->result_array();
	$output = "<select id='id_province' class='contact_input' name='id_province'>";
	foreach($row as $row):
		if($selected):
			if($row["id_province"]==$selected):
				$output .= "<option value='".$row["id_province"]."' selected='selected'>".$row['nm_province']."</option>";
			else:
				$output .= "<option value='".$row["id_province"]."'>".$row['nm_province']."</option>";
			endif;
	    else:
			$output .= "<option value='".$row["id_province"]."'>".$row['nm_province']."</option>";
		endif;
	endforeach;
	$output .= "</select>";
	return $output;
}


?>